﻿using Digitalmes.ApiService.Hubs;
using Digitalmes.Application;

namespace Digitalmes.ApiService.Controllers;

/// <summary>
/// Channel 通信，仅测试
/// </summary>
[AllowAnonymous, NoApiSecurity, NoJsonResult, NoAuditLog]
public sealed class TestChannelController : ApiController
{
    private readonly IHubContext<ChannelHub, IChannelClient> _hubContext;

    public TestChannelController(IHubContext<ChannelHub, IChannelClient> hubContext)
    {
        _hubContext = hubContext;
    }

    [HttpPost("SendMessage")]
    public async Task SendMessage()
    {
        ClentMessage message = new()
        {
            LineCode = "L1",
            OpCode = "OP010",
            State = 20,
            ErrorMessage = "测试程序",
            InnerErrorCode = 1007,
            Mode = "inbound",
            Target = new
            {
                Status = "OK",
            },
        };
        await _hubContext.Clients.All.ReceiveMessage(message); // 广播
    }
}
